package com.hc.dao;

import com.hc.bean.Pager;
import com.hc.bean.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserInfoDao {
    /*查询所有用户信息*/
    @Select("<script>" +
            " select * from user_info " +
            " <if test='userName!= null'>" +
            " <where>" +
            " userName like concat('%',#{userName},'%') " +
            " </where>" +
            " </if>" +
            " limit #{pager.firstLimitParam},#{pager.pageRows}" +
            " </script>")
    public List<UserInfo> getUserInfo(@Param("userName") String userName, @Param("pager")Pager pager);

    /*查询所有用户信息行数*/
    @Select("<script>" +
            " select count(*) from user_info " +
            " <where>" +
            " <if test='userName!= null'>" +
            " userName like concat('%',#{userName},'%') " +
            " </if>" +
            " </where>" +
            " </script>")
    public int getUserInfoCount(String userName);

    /*修改用户可用状态*/
    @Update("update user_info set status=#{status} where id in (${ids})")
    public int setIsEnableUser(@Param("status") int status,@Param("ids")String ids);

    /*查询所有有订单记录的用户*/
    @Select("select * from user_info where id in (select uid from order_info)")
    public List<UserInfo> getOrderUser();

    /*查询所有状态为启用的用户*/
    @Select("select * from user_info where status=1")
    public List<UserInfo> getValidUser();

    /*根据ID查询*/
    @Select("select * from user_info where id=#{id}")
    public UserInfo getUserInfoById(int id);

    /*添加新用户*/
    @Insert("insert into user_info values(#{id},#{userName},#{password},#{realName},#{sex},#{address},#{email},#{regDate},#{status})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    public int addUser(UserInfo userInfo);
}
